# 指定CMake最低版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(ctp_project)

# 非调试时 去掉这两个配置
# 设置编译选项，添加调试信息
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")

# 设置构建类型为Debug
set(CMAKE_BUILD_TYPE Debug)
# ===================================

# 添加yaml-cpp依赖
find_package(yaml-cpp REQUIRED)

# 添加线程库
find_package(Threads REQUIRED)

# 添加include目录
include_directories(
    ${CMAKE_SOURCE_DIR}
)

# 添加CTP库的路径
link_directories(
    ${CMAKE_SOURCE_DIR}/ctp    # CTP库所在目录
)

# 添加可执行文件目标
add_executable(${PROJECT_NAME}
    main.cpp
    mduserhandle.cpp
    tradehandler.cpp
    tcp_server.cpp
)

# 链接库
target_link_libraries(${PROJECT_NAME} 
    PRIVATE 
    yaml-cpp
    ${CMAKE_THREAD_LIBS_INIT}  # pthread
    thostmduserapi_se         # CTP的行情库
    thosttraderapi_se         # CTP的交易库
)

# 查找iconv库
find_library(ICONV_LIBRARY NAMES iconv)
if(NOT ICONV_LIBRARY)
    # 在某些系统上(如Linux)，iconv是glibc的一部分
    # 不需要单独链接
    set(ICONV_LIBRARY "")
endif()

# 添加到目标链接库中
target_link_libraries(${PROJECT_NAME} 
    PRIVATE 
    ${ICONV_LIBRARY}
) 